#include "File.h"
#include "../LuaVM/LuaDefine.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdarg.h>

bool FileLoad(const char *pcszPath, char **ppFileBuffer, int bText, void* pvOpenFile)
{
	int bRet = false;
	long nCount = 0;
	long size = 0;
	char* m_pBuffer = nullptr;

	FILE* pFile = fopen(pcszPath,"rb");
	LOG_PROCESS_ERROR(pFile);
	fseek(pFile, 0, SEEK_END);
	size = ftell(pFile);
	LOG_PROCESS_ERROR(size); 
	fseek(pFile, 0, SEEK_SET);

	m_pBuffer = (char*)malloc(size + 1);
	fread(m_pBuffer, sizeof(char), size, pFile);
	//m_pBuffer[size + 1] = "\0";

	*ppFileBuffer = m_pBuffer;
	bRet = true;
	
Exit0:
	fclose(pFile);
	return bRet;
}

long FileTell(const char* pcsFileName)
{
	FILE* pFile = fopen(pcsFileName, "rb");
	long ret = 0;
	fseek(pFile, 0, SEEK_END);
	ret = ftell(pFile);
	fseek(pFile, 0, SEEK_SET);
	fclose(pFile);
	return ret;
}